package io.finer.erp.jeecg.bas.mapper;

import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import io.finer.erp.jeecg.stock.entity.StkInventory;
import io.finer.erp.jeecg.stock.entity.StkMaterielStorage;
import io.finer.erp.jeecg.stock.vo.SumQtyVo;
import io.finer.erp.jeecg.stock.vo.SumQtyVo2;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import io.finer.erp.jeecg.bas.entity.BasMaterial;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * @Description: 物料
 * @Author: jeecg-boot
 * @Date:   2020-08-25
 * @Version: V1.0
 */
public interface BasMaterialMapper extends BaseMapper<BasMaterial> {
	
	public List<BasMaterial> selectMaterialByCategoryId(String categoryId);
	
	public List<BasMaterial> selectDistinctMaterialByCategoryId(@Param("categoryId")String categoryId);

	@Select("SELECT e.material_id FROM stk_io_bill_entry e LEFT JOIN stk_io_bill b ON e.mid = b.id where material_id IN (SELECT id FROM bas_material WHERE category_id = #{categoryId}) AND b.source_id in(SELECT ib.source_id FROM stk_io_bill_entry be LEFT JOIN stk_io_bill ib ON be.mid=ib.id LEFT JOIN bas_material bm ON be.material_id=bm.id WHERE bm.supplier=#{suplierId})")
	public List<String> getSuplierMaterialId(@Param("suplierId")String suplierId, @Param("categoryId")String categoryId);
    @Select("SELECT id FROM bas_material mate WHERE mate.id in (select material_id from stk_inventory WHERE qty >0 and is_enabled=1 and warehouse_id not in ('1310776802430914562','1316197125803118594')) and mate.category_id=#{categoryId}")
	public List<String> getInventoryMaterialIdsByCategory(@Param("categoryId")String categoryId);

    public Page<StkMaterielStorage> getMaterials(IPage<StkMaterielStorage> page,@Param("warehouseId") String warehouseId,
												 @Param("parameter") List<String> parameter,@Param("materialCode")String materialCode,
												 @Param("width_begin") String width_begin,@Param("width_end")String width_end,
												 @Param("length_begin")String length_begin,@Param("length_end")String length_end,@Param("order")String order);
    
    public List<StkMaterielStorage> getMaterialsCount(@Param("warehouseId") String warehouseId,
			 @Param("parameter") String parameter,@Param("materialCode")String materialCode,
			 @Param("width_begin") String width_begin,@Param("width_end")String width_end,
			 @Param("length_begin")String length_begin,@Param("length_end")String length_end,@Param("order")String order);


	 public List<StkMaterielStorage> sumQty(@Param("storage") StkMaterielStorage storage);
	 
	 public IPage<StkInventory> getSumQtyDetail(Page<StkInventory> page, @Param("storage") StkMaterielStorage storage);

	public List<SumQtyVo> sumQtyXls(@Param("materialId") String materialId ,
									@Param("pid")String pid,@Param("materialName") String materialName);

	public List<SumQtyVo2> sumQtyXls2(@Param("materialId") String materialId ,
									  @Param("pid")String pid, @Param("materialName") String materialName);
	/**
	 * @Description 根据物料分类id查询不在废品库和成品库的实时库存物料id
	 * @param categoryId
	 * @return
	 * Create at: 2021-06-23 11:45:07
	 * @author: xzs
	 * Revision:
	 *    2021-06-23 11:45:07 - first revision by xzs
	 *
	 */
	@Select("SELECT id FROM bas_material mate WHERE mate.id in (select material_id from stk_inventory WHERE qty >0 and is_enabled=1 and warehouse_id not in ('1310776802430914562','1310776404844449794')) and mate.category_id=#{categoryId}")
	public List<String> getInvenMaterialIdsByCateId(@Param("categoryId")String categoryId);

	@Select("select * from bas_material where id in (select material_id from stk_io_bill_entry where mid in (select id from stk_io_bill where stk_io_bill.stock_io_type='101')) and id=#{materialId} limit 1")
	public BasMaterial getPurchaseMaterial(@Param("materialId")String materialId);


}
